pub fn is_happy(n: i32) -> bool {
    let mut nexts = vec![n];
    let mut m = n;

    loop {
        m = next(m);
        if m == 1 {
            return true;
        }
        if nexts.contains(&m) {
            return false;
        }
        nexts.push(m);
    }
}

pub fn next(n: i32) -> i32 {
    let s = n.to_string();
    let chars = s.chars();
    let mut sum = 0;
    for char in chars {
        let num: i32 = char.to_string().parse().unwrap_or(0);
        sum += num * num;
    }
    return sum;
}
